﻿using UnityEngine;
using System.Collections;

public class TimeBar : MonoBehaviour {

	bool Trigger= false;

	public float ElapseSpeed ;
	float fScrollX;

	void Start(){
		GetComponent<UISprite> ().atlas.GetSprite("Timebar").x = 0;
		GetComponent<UISprite> ().atlas.GetSprite("Timebar 1").x = 0;
	}

	void Update(){
		fScrollX += Clock.fElapseSpeed ;
		GetComponent<UISprite> ().GetAtlasSprite().x = (int)fScrollX;
		if (Trigger) {
			GetComponent<UISprite> ().spriteName = "Timebar";
			Trigger = false;
		} else {
			GetComponent<UISprite> ().spriteName = "Timebar 1";
			Trigger = true;
		}

		if (GetComponent<UISprite> ().GetAtlasSprite ().x >= 1320) {
			GetComponent<UISprite> ().atlas.GetSprite("Timebar").x = 0;
			GetComponent<UISprite> ().atlas.GetSprite("Timebar 1").x = 0;
			fScrollX = 0;
		}

		if (Clock.iHour >= 6 && Clock.iHour <= 18)
			transform.FindChild ("Timer").GetComponent<UISprite> ().color = new Color (29/255f, 26/255f, 24/255f);
		else
			transform.FindChild ("Timer").GetComponent<UISprite> ().color = new Color (189/255f, 173/255f, 160/255f);

		//GetComponent<UISprite> ().MakePixelPerfect ();
	}
}
